﻿using System;
using System.Collections;
using System.Data;
using Lib.Data;
using Lib.Utils;

namespace SysObj
{
    public class Kho_TonDau : Lib.Bases.BaseClass
    {
        public DateTime Ngay { get; set; }
        public DataTable Detail { get; set; }

        #region  Constructors
        public Kho_TonDau()
        {
            m_DataLayer = new Lib.Data.DataLayer();
        }

        #endregion

        #region Methods
        public override void ResetData()
        {
        }


        public override void FillData(DataRow row)
        {
        }

        public override DataTable LoadData()
        {
            return m_DataLayer.ExecDataTable("SP_KHO_TONDAU", "Command,Ngay", "LoadData", Cvert.ToShortDate(Ngay));
        }

        public override void OnUpdate()
        {
            Hashtable output = null;
            string s_ParamName = "";
            object[] o_ParamValue = null;
            try
            {
                m_DataLayer.BeginTransaction();

                m_DataLayer.ExecNonQuery("SP_KHO_TONDAU", "Command,Ngay", "Delete", Cvert.ToShortDate(Ngay));

                foreach (DataRow row in Detail.Rows)
                {
                    Lib.Data.ParamHolder.ClearAll();
                    Lib.Data.ParamHolder.AddParam("Command", "Insert");
                    Lib.Data.ParamHolder.AddParam("Ngay", Cvert.ToShortDate(Ngay));
                    Lib.Data.ParamHolder.AddParam("IdHangHoa", Cvert.ToInt32(row["IdHangHoa"], 0));
                    Lib.Data.ParamHolder.AddParam("Rong", Cvert.ToInt32(row["Rong"], 0));
                    Lib.Data.ParamHolder.AddParam("Dai", Cvert.ToInt32(row["Dai"], 0));
                    Lib.Data.ParamHolder.AddParam("SoThanh", Cvert.ToDecimal(row["SoThanh"], 0));
                    Lib.Data.ParamHolder.AddParam("KhoiLuong", Cvert.ToDecimal(row["KhoiLuong"], 0));
                    Lib.Data.ParamHolder.AddParam("SoKien", Cvert.ToString(row["SoKien"], ""));
                    Lib.Data.ParamHolder.AddParam("GhiChu", Cvert.ToString(row["GhiChu"], ""));
                    Lib.Data.ParamHolder.GetParams(ref s_ParamName, ref o_ParamValue);
                    m_DataLayer.ExecNonQuery("SP_KHO_TONDAU", s_ParamName, ref output, o_ParamValue);
                }

                m_DataLayer.CommitTransaction();
            }
            catch (Exception ex)
            {
                m_DataLayer.RollbackTransaction();

                throw ex;
            }
        }

        public override void OnDelete()
		{
			string s_ParamName = "";
			object[] o_ParamValue = null;
			try
			{
                //Lib.Data.ParamHolder.ClearAll();
                //Lib.Data.ParamHolder.AddParam("Command", "Delete");
                //Lib.Data.ParamHolder.AddParam("Ngay", );
                //Lib.Data.ParamHolder.GetParams(ref s_ParamName,ref o_ParamValue);
                //m_DataLayer.ExecNonQuery("SP_KHO_TONDAU", s_ParamName, o_ParamValue);
			}
			catch( Exception ex)
			{
				throw ex;
			}
		}

        #endregion
    }
}
